home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / ZBRAC.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  759b  |  31 lines

  1. PROCEDURE zbrac(VAR x1,x2: real; VAR succes: boolean);
  2. (* Programs using routine ZBRAC must externally define a
  3. function fx(x:real):real which is to be bracketed. *)
  4. LABEL 99;
  5. CONST
  6.    factor=1.6;
  7.    ntry=50;
  8. VAR
  9.    j: integer;
  10.    f2,f1: real;
  11. BEGIN
  12.    IF (x1 = x2) THEN BEGIN
  13.       writeln('pause in routine ZBRAC');
  14.       writeln('you have to guess an initial range'); readln
  15.    END;
  16.    f1 := fx(x1);
  17.    f2 := fx(x2);
  18.    succes := true;
  19.    FOR j := 1 TO ntry DO BEGIN
  20.       IF (f1*f2 < 0.0) THEN GOTO 99;
  21.       IF (abs(f1) < abs(f2)) THEN BEGIN
  22.          x1 := x1+factor*(x1-x2);
  23.          f1 := fx(x1)
  24.       END ELSE BEGIN
  25.          x2 := x2+factor*(x2-x1);
  26.          f2 := fx(x2)
  27.       END
  28.    END;
  29.    succes := false;
  30. 99:   END;
  31.